package userctr

import (
	"auusoft/AuuWiki/Models"
	"auusoft/AuuWiki/controllers"
	"crypto/md5"
	"encoding/hex"
	//"fmt"
)

type UserAddController struct {
	controllers.RootController
}

func (this *UserAddController) Post() {
	this.CheckSession()

	this.Ctx.Request.ParseForm()
	username := this.Ctx.Request.Form.Get("username")
	password := this.Ctx.Request.Form.Get("password")
	ifadmin := this.Ctx.Request.Form.Get("ifadmin")

	if ifadmin == "on" {
		ifadmin = "true"
	} else {
		ifadmin = "false"
	}

	h := md5.New()
	h.Write([]byte(password))
	userinfo := models.UserInfo{}

	userinfo.Password = hex.EncodeToString(h.Sum(nil)) // 输出加密结果
	//fmt.Println("%s\n", userinfo.Password)

	userinfo.UserName = username
	userinfo.Ifadmin = ifadmin
	models.InsertUserInfo(userinfo)

	//客户端用ajax接收数据，所以随便发点啥回去就行了
	this.Ctx.WriteString("ok")
	//this.Ctx.Redirect(302, "/userctr/userlist")
}
